import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";
//npm install -D unplugin-auto-import unplugin-vue-components
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";

// 后端服务器配置
const backendConfig = {
  //target: "http://www.zhaojinchuan.com:8080/", // 后端服务器地址
  target: "http://localhost:8080", // 后端服务器地址  
  //target: "http://192.168.2.103:8081/", // 后端服务器地址
  changeOrigin: true,
};

export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "./src"),
    },
  },
  server: {
    proxy: {
      "/a": backendConfig,
    },
  },
  define: {
    "import.meta.env.BACKEND_URL": JSON.stringify(backendConfig.target),
  },
});
